<template>
  <div class="mainor">
    <div class="mainsu">
      <div class="main_spac1">
        <div class="main_white padding10 paddingBottom20">
          <div class="main_crumbs boxdq">
            <div class="main_crumbs_l">
              <a href="javascript:;" @click="$router.back(-1)">
                <i class="el-icon-arrow-down"></i>返回
              </a>
              <em>|</em>
              <span>首页</span>
            </div>
          </div>
          <div class="mainor_form marginTop15">
            <el-form
              :inline="true"
              :model="form"
              class="demo-form-inline"
              ref="userListFrom"
              label-width="80"
            >
              <el-form-item label="标题" prop="title">
                <el-input
                  placeholder="标题"
                  class="wid220"
                  v-model.trim="form.title"
                >
                </el-input>
              </el-form-item>
              <el-form-item label="来源" prop="site_id">
                <el-select
                  v-model.trim="form.site_id"
                  placeholder="来源"
                  class="wid220"
                >
                  <el-option label="所有" value=""></el-option>
                  <el-option
                    v-for="site in site"
                    :key="site.id"
                    :label="site.name"
                    :value="site.id"
                  ></el-option>
                </el-select>
              </el-form-item>
              <el-form-item label="采集时间" prop="createTime">
                <el-date-picker
                  v-model="createTime"
                  type="daterange"
                  class="time220"
                  :editable="false"
                  unlink-panels
                  range-separator="至"
                  start-placeholder="开始日期"
                  end-placeholder="结束日期"
                  value-format="yyyy-MM-dd"
                  :clearable="false"
                  :picker-options="pickerOptions"
                />
              </el-form-item>

              <el-form-item>
                <el-button
                  class="reset marginLeft10"
                  type="primary"
                  @click="reset"
                  >重置</el-button
                >
                <el-button
                  type="primary"
                  @click="getArticleList"
                  :loading="loading"
                  >搜索</el-button
                >
              </el-form-item>
            </el-form>
          </div>

          <div class="main_table marginTop10" style="min-height: 550px">
            <el-table
              ref="multipleTable"
              v-loading="loading"
              :data="list"
              element-loading-text="加载中"
              fit
              border
              highlight-current-row
              :header-cell-class-name="this.$verticaline"
            >
              <el-table-column label="序号" show-overflow-tooltip width="80">
                <template slot-scope="scope">
                  {{ scope.$index + 1 }}
                </template>
              </el-table-column>
              <el-table-column
                label="标题"
                show-overflow-tooltip
                prop=""
                min-width="300"
              >
                <template slot-scope="scope"
                  ><span class="jump_title" @click="handleJump(scope)">
                    {{ scope.row.title }}
                  </span></template
                >
              </el-table-column>
              <el-table-column
                show-overflow-tooltip
                label="来源"
                width="220"
                prop=""
              >
                <template slot-scope="scope"
                  ><span>
                    {{ site[scope.row.site_id].name }}
                  </span></template
                >
              </el-table-column>

              <el-table-column
                label="采集时间"
                prop=""
                width="200"
                fixed="right"
              >
                <template slot-scope="scope"
                  ><span>
                    {{
                      scope.row.created_at
                        ? parseTime(scope.row.created_at)
                        : ""
                    }}
                  </span></template
                >
              </el-table-column>
            </el-table>
          </div>
          <div class="main_page boxdq">
            <div></div>
            <!-- 分页 -->
            <div class="main_page_r">
              <el-pagination
                :current-page="current.page"
                :page-sizes="[20, 50, 100]"
                :page-size="limit"
                layout="total, sizes, prev, pager, next, jumper"
                :total="totalCount"
                background
                @size-change="changeLimit"
                @current-change="changePage"
              />
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapGetters } from "vuex";

import { getTender } from "@/api/index/index";
import { apiUrl, objKeySort, Md5 } from "@/utils/public";
import { puzzleImg } from "@/api/currency";
import { parseTime } from "@/utils/index";
import dateOption from "@/options/dateOption";

export default {
  computed: {
    ...mapGetters(["avatar"]),
  },
  data() {
    return {
      parseTime,
      pickerOptions: dateOption,
      input4: "",
      puzzleImg,
      createTime: [],
      // 分页
      current: {
        page: 1,
        per_page: 20,
      },
      limit: 20,
      totalCount: 1,
      loading: false,
      form: {
        title: "",
        site_id: "",
      },
      site: {},
      // 列表数据
      list: [],
    };
  },
  mounted() {},
  created() {
    // 列表
    this.getTender();
  },
  methods: {
    // 搜索
    getArticleList() {
      this.current.page = 1;
      this.getTender();
    },
    // 重置
    reset() {
      this.$refs["userListFrom"].resetFields();
      this.createTime = [];
      this.getArticleList();
    },

    // 分页
    changeLimit(pageSize) {
      this.current.per_page = pageSize;
      this.getTender();
    },
    changePage(page) {
      this.current.page = page;
      this.getTender();
    },
    // 列表
    getTender() {
      this.loading = true;
      let data = Object.assign(
        {
          sign: Md5(
            objKeySort(Object.assign(apiUrl().name)) + apiUrl().appsecret
          ),
        },
        apiUrl().name,
        this.list_form(),
        this.current
      );
      getTender(data).then((res) => {
        if (res.errcode == 0) {
          this.list = res.data.list.data;
          this.site = res.data.site;
          this.loading = false;
          this.totalCount = res.data.list.total;
        } else {
          this.$message.error(res.errmsg);
        }
      });
    },
    list_form() {
      let form = JSON.parse(JSON.stringify(this.form));
      form.start_time = this.createTime[0] ? this.createTime[0] : "";
      form.end_time = this.createTime[1] ? this.createTime[1] : "";

      return form;
    },
    // 跳转
    handleJump(scope) {
      let url = scope.row.url;
      window.open(url);
    },
  },
};
</script>
<style lang="scss" scoped>
@import "@/styles/variables.scss";

.back {
  display: inline-block;
  padding-top: 8px;
  font-size: 14px;
  color: #606266;
  cursor: pointer;
  &:hover {
    color: #03a98e;
  }
}
.dot-box {
  width: 100%;
  height: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
}
.dot {
  display: block;
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background-color: red;
}
.el-image {
  width: 80px;
  margin-right: 20px;
}
.main_table /deep/.el-table--small td .cell {
  min-height: 45px;
  height: auto;
  display: flex;
  align-items: center;
}
.main_table /deep/.el-table--small td {
  &:nth-child(4) {
    .cell {
      justify-content: center;
    }
  }
}
// 支付状态
.success {
  color: $order_color3;
}
.unpaid {
  color: $colour_red;
}
// 订单状态
.order1 {
  color: $order_color1;
}
.order2 {
  color: $order_color2;
}
.order3 {
  color: $order_color3;
}
.order4 {
  color: $order_color4;
}
.jump_title {
  cursor: pointer;

  &:hover {
    color: #03a98e;
  }
  &:visited {
    color: red;
  }
}
</style>
